package org.example.rocket;

import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.TimeUnit;

public class Producer {

    public static DefaultMQProducer producer = null;


    public static void init() throws Exception{
        producer = new DefaultMQProducer("groupA");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();
    }


    public static void send(String message,String topic) throws Exception{
        Message msg = new Message(topic, message.getBytes());
        SendResult result = producer.send(msg);
        System.out.println("发送结果："+result);
    }
}
